package com.briup.day07;

/**
 * @author lining
 * @date 2024/1/16 15:13
 */
public class Student {
    private int id;//学号
    private String name;//姓名
    private String city;//户籍
    static {
        //类加载 自动执行静态代码块 并且只执行一次
        System.out.println("静态代码块");
        school = "华东交大";
        //this不能放在静态代码块中使用
        //静态中不能调用非静态属性和方法
        Student s = new Student();//创建一个对象
    }
    //执行顺序：和加载顺序（位置）
    private static String school = "太原科技";//学校信息




    {
        System.out.println("构造代码块");
        //代码块：可以为属性进行赋值操作
        this.city = "南昌";
    }
    public Student() {
        //this.city = "南昌";//默认赋值
    }

    public Student(int id, String name) {
        this.id = id;
        this.name = name;
        //this.city = "南昌";
    }

    public Student(int id, String name, String city) {
        this.id = id;
        this.name = name;
        this.city = city;
    }

    public int getId() {
        return id;
    }

    public static String getSchool() {
        return school;
    }

    public static void setSchool(String school) {
        Student.school = school;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", city='" + city + '\'' +
                '}';
    }
}
